
local rect = ac.rect.j_rect('base')
local point = rect:get_point()



--迷雾
ac.game:fog(false)
ac.game:fogmask(false)


ac.sync:event '回城'(function(_,player)
    local hero = player.hero
    if hero then
        player:notify('玩家-传送',player,player.point1)
    end
end)


ac.game:event '玩家-传送'(function(_,player,point)
    local unit = player.hero
    local point = point:get_point()
    unit:set_point(point,true)
    unit:issue_order('stop')
    player:set_camera(point)
    player:select_unit(unit)
end)


ac.game:event '游戏-新的一天'(function()
    ac.game:set_time(12)
end)

ac.game:event '游戏-进入黑夜'(function()
    ac.game:set_time(12)
end)

if ac.message.client_online then
    -- local win_w = japi.DzGetWindowWidth()
    -- local win_h = japi.DzGetWindowHeight()
    -- if japi.IsWindowMode() then
    --     local w = math.max(win_w / 0.8, 1920)
    --     local h = w * 1080 / 1920
    --     if h>win_h*0.9 then
    --         h = math.min(win_h * 0.8, 1080)
    --         w = h*1920 / 1080
    --     end
    --     japi.SetWindowSize(w,h)
    -- else
    --     japi.SetWindowSize(win_w,win_h)
    -- end
    -- --宽屏
    -- japi.DzEnableWideScreen(true)
end

ac.each_player(function(player)
    local rect1 = ac.rect.j_rect('P'..player.id)
    local rect2 = ac.rect.j_rect('PL'..player.id)
    local rect3 = ac.rect.j_rect('YC'..player.id)
    local rect3_1 = ac.rect.j_rect('J'..player.id)
    local rect4 = ac.rect.j_rect(('CD1_%s'):format(player.id))
    local rect5 = ac.rect.j_rect(('T%s'):format(player.id))
    local rect6 = ac.rect.j_rect(('shop%s_1'):format(player.id))
    local rect7 = ac.rect.j_rect(('shop%s_2'):format(player.id))
    local rect8 = ac.rect.j_rect(('shop%s_3'):format(player.id))
    local point = rect1:center()

    player.rect1 = rect1
    player.rect2 = rect3_1
    player.rect3 = rect3
    player.rectT = rect5
    player.shop1 = rect6:center()
    player.shop2 = rect7:center()
    player.shop3 = rect8:center()

    player.point1 = rect2:center()
    player.cd_point = rect4:center()

end)


ac.game:event '英雄-私人挑战'(function(_,hero,name,time,func,func2)
    local point1 = hero:get_point()
    local angle = math.random(360)

    ac.mover('line')
    {
        start = hero:get_launch_point(),
        angle = angle,
        distance = 600,
        speed = 400,
        arc = 0.15,
        size = 2,
        block = true,
        model = [[Abilities\Weapons\FaerieDragonMissile\FaerieDragonMissile.mdl]],
        on_block = function(mvr)
            mvr:remove()
        end,
        on_remove = function(mvr)
            local unit = ac.player[12]:create_unit(name,mvr:get_point())
            unit:set('魔法上限',time)
            unit:set('魔法恢复',-1)
            unit:set_data('能量贴图',[[core\hpbar\黄条.tga]])
            --unit:add_buff 'Boss出场'{time = 2}
            if func2 then
                func2(unit)
            end
            unit:issue_order('attack',hero)
            unit:event '单位-死亡'(function()
                unit:remove()
                func(true)
            end)
            unit:event '单位-即将移除'(function()
                if unit:is_alive() then
                    func(false)
                end
            end)
            unit:wait(time*1000,function()
                unit:remove()
            end)
            unit:loop(1000,function()
                unit.name = ('%s(|cffffff00%s|r)'):format(name,time)
                time = time - 1
            end):on_timer()
            
        end,
    }
end)

